package com.example.assignment01_javaee.Service.Impl;

import com.example.assignment01_javaee.Dao.EmployeeDao;
import com.example.assignment01_javaee.Entity.Employee;
import com.example.assignment01_javaee.Service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    EmployeeDao employeeDao;
    public List<Employee> getAllEmployees(){

        return employeeDao.getAllEmployees();
    }

    public Employee getEmployeeById(String employeeId){

        return employeeDao.getEmployeeById(employeeId);
    }
    public String createEmployee(Employee employee){

        employeeDao.createEmployee(employee);

        return "创建成功!";
    }
    public String updateEmployeeById(Employee employee){

        employeeDao.updateEmployeeById(employee);

        return "更新成功！";
    }
    public String updateEmployeePositionById(String position, String employeeId){

        Map<String, String> map = new HashMap<>();
        map.put("position",position);
        map.put("employeeId",employeeId);

        employeeDao.updateEmployeePositionById(map);

        return "更新成功！";
    }

    public String deleteEmployeeById(String employeeId){
        Employee employee = employeeDao.getEmployeeById(employeeId);
        if(employee != null){
            employeeDao.deleteEmployeeById(employeeId);
            return "删除成功!";
        }
        return "该职员不存在！";
    }
}
